package threading;

public class ThreadDemo4 {
    public static void main(String[] args) {

        Thread thread = new Thread( () -> {
                // currentThread 是获取到当前线程实例
                // 此处currentThread 得到的对象就是t
                // isInterrupted 就是t 对象里自带的一个标志位
            while (!Thread.currentThread().isInterrupted()){
                System.out.println("hello t");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        } );
        thread.start();

        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        // 把t 内部的标志位 设置成 true
        thread.interrupt();

    }
}
